package com.wjh.dao;

import com.wjh.pojo.UserEntity;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserDao {

	@Select("select  id,username,password,phone,email,created,updated,token,openid from mb_user where id =#{userId}")
	UserEntity findByID(@Param("userId") Integer userId);

	@Insert("Insert  INTO `mb_user`  (username,password,phone,email,created,updated,token,openid) VALUES (#{username}, #{password},#{phone},#{email},#{created},#{updated},#{token},#{openid});")
	Integer insertUser(UserEntity userEntity);

	@Update("UPDATE mb_user u SET u.username = #{username}, u.password = #{password}, u.phone = #{phone}, u.email = #{email}, u.created = #{created}, u.updated   = #{updated},u.token = #{token},u.openid = #{openid} WHERE u.id=#{id};")
	Integer updataUser(UserEntity userEntity);

	@Update("UPDATE mb_user u SET u.openid = #{openid} WHERE u.id=#{id};")
	Integer updataUserOpenid(@Param("openid") String openid ,@Param("id") Integer id);

	@Update("UPDATE mb_user u SET u.token = #{token},u.updated = now() WHERE u.id=#{id};")
	Integer updataUserToken(@Param("token") String token ,@Param("id") Integer id);

	@Select("select  id,username,password,phone,email,created,updated,token,openid from mb_user where  username=#{username}")
	UserEntity findByUsername(@Param("username") String username);

	@Select("select  id,username,password,phone,email,created,updated,token,openid from mb_user where  openid=#{openid}")
	UserEntity findUserByOpenId(@Param("openid") String openid);

}